import 'package:drift/drift.dart';
import 'package:drift/native.dart';
import 'package:flutter_crud_test_amir_rabbani/data/local/dao/customer_dao.dart';
import 'dart:io';

// import 'package:drift/web.dart';
import 'package:path/path.dart' as p;
import 'package:path_provider/path_provider.dart';

part 'my_database.g.dart';

@DriftDatabase(tables: [CustomerDao])
class AppDatabase extends _$AppDatabase {
  AppDatabase() : super(_openConnection());

  @override
  int get schemaVersion => 1;
}

LazyDatabase _openConnection() {
  return LazyDatabase(() async {
    final dbFolder = await getApplicationDocumentsDirectory();
    final file = File(p.join(dbFolder.path, 'app.db'));
    return NativeDatabase(
      file,
      logStatements: true,
    );
    // return WebDatabase('db');
  });
}
